package com.jinlei.springcouldconsumer.controller;

import com.jinlei.springcouldconsumer.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
@Api(tags = "消费者管理")
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;
    @PostMapping("/get")
    @ApiOperation("查询用户")
    @ApiImplicitParam(name = "id",value = "用户编号",required = true)
    @RequestMapping(value = "/consumer/hello",method = RequestMethod.POST)
    public User getUserById(@RequestParam(required = true)int id){
            User user=new User();
            user.setId(1);
            user.setUsername("张三");
            return user;
        //调用SpringCloud服务提供者的服务 String.class返回类型
//      return   restTemplate.getForEntity("http://localhost:8080/service/hello",String.class).getBody();
    }
    @PostMapping("/consumer/user")
    public User getUser(@RequestBody(required = true) User user){
        User user1=new User(1,"龙桑");
        return user1;
    }
}
